import {createDecorator} from 'vue-class-component'

export function watch(name, options) {
  const {deep = false, immediate = false} = options
  return createDecorator(function (componentOptions, key) {
    if (typeof componentOptions.watch !== 'object') {
      componentOptions.watch = Object.create(null)
    }

    // let proxyHandler = (...args) => {
    //   // handler(args)
    //   console.log('call handler', componentOptions, 'args', args)
    //   if (componentOptions.methods[key] instanceof Function) {
    //     componentOptions.methods[key](args)
    //   }
    // }
    componentOptions.watch[name] = {handler: key, deep, immediate}
  })
}
